package genericity;

import java.util.ArrayList;
import java.util.List;

/**
 * 变长参数泛型
 *
 * @author Panbo Guo
 * @date 2021/5/21
 */
public class IndefiniteParamTest {

    private static abstract class Service<T> {
        public void testArray(T... arr) {
            System.out.println("AService.testArray -> " + arr.getClass());
            getBService().testObject(arr);
        }

//        void testObject(T obj) {
////        String obj = (String) obj;
//            testArray(obj);
//        }
        abstract void testObject(T obj);

        abstract Dao<T> getBService();
    }

    private static class ServiceImpl extends Service<String> {

        private final Dao<String> dao = new DaoImpl();

        void testObject(String obj) {
            testArray(obj);

            List<String> list = new ArrayList<>();
            for (int i = 0; i < 10; i++) {
                String str = "i" + i;
                list.add(str);
            }
        }

        @Override
        Dao<String> getBService() {
            return dao;
        }
    }

    private interface Dao<T> {
         void testObject(T... arr);
    }


    private static class DaoImpl implements Dao<String> {
        @Override
        public void testObject(String... arr) {
            System.out.println("DaoImpl.testObject -> " + arr.getClass());
        }
    }

    public static void main(String[] args) {
        Service<String> service = new ServiceImpl();
        service.testObject("1");
    }
}
